home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Think Class Libraries / Expander / Expander Classes / CExpanderHeader.cp < prev    next >
Encoding:
Text File  |  1994-11-30  |  3.4 KB  |  153 lines  |  [TEXT/KAHL]

  1. /***********************************************************************************
  2.     CExpanderHeader.cp
  3.  
  4.     Copyright © 1994 B-Ray Software. All rights reserved.
  5.     Developed using Symantec C++ 7.0.2 and Symantec's TCL library.
  6.     Portions of this code courtesy Symantec, Inc.
  7.  
  8.     This code may be freely distributed as long as this notice remains. This code
  9.     may not be used in any commercial software without the consent of B-Ray Software.
  10.  
  11.     ---
  12.  
  13.     CExpanderHeader class provides a label and a button for a CExpander object.
  14.  
  15. ***********************************************************************************/
  16. #include <Commands.h>
  17.  
  18. #include "CExpanderButton.h"
  19. #include "CExpanderLabel.h"
  20. #include "ExpanderMessages.h"
  21.  
  22. #include "CExpanderHeader.h"
  23.  
  24.  
  25. short const CExpanderHeader::kExpanderButtonSize = 16;
  26.  
  27.  
  28. TCL_DEFINE_CLASS_D1( CExpanderHeader, CExpanderPane );
  29.  
  30.  
  31. /*
  32.  * CExpanderHeader constructor
  33.  *
  34.  * Default constructor - should only be used when created by a file read.
  35.  */
  36.  
  37. CExpanderHeader :: CExpanderHeader() : CExpanderPane()
  38. {
  39.     itsLabel = NULL;
  40.     itsButton = NULL;
  41.  
  42.     TCL_END_CONSTRUCTOR
  43. }
  44.  
  45.  
  46. /*
  47.  * CExpanderHeader constructor
  48.  *
  49.  * Normal constructor - should always be used when a new object is created
  50.  * in code.
  51.  */
  52.  
  53. CExpanderHeader :: CExpanderHeader( CView *anEnclosure, CBureaucrat *aSupervisor, 
  54.                                   short aWidth, short aHeight, short aHLoc, short aVLoc, 
  55.                                   SizingOption aHSizing, SizingOption aVSizing )
  56.             : CExpanderPane( anEnclosure, aSupervisor, aWidth, aHeight, aHLoc, aVLoc,
  57.                               aHSizing, aVSizing )
  58. {
  59.     itsLabel = NULL;
  60.     itsButton = NULL;
  61.  
  62.     SetWantsClicks( TRUE );        // want clicks for our button
  63.  
  64.     try_ {
  65.         MakeComponents();        // create button and label panes
  66.     }
  67.     catch_all_() {
  68.         throw_same_();
  69.     }
  70.     end_try_;
  71. }
  72.  
  73.  
  74. /*
  75.  * CExpanderHeader destructor
  76.  *
  77.  * Just a place-holder for Inspector
  78.  */
  79.  
  80. CExpanderHeader :: ~CExpanderHeader()
  81. {
  82.     TCL_START_DESTRUCTOR
  83. }
  84.  
  85.  
  86. /*
  87.  * IExpanderHeader method
  88.  *
  89.  * Private method that creates our button and label panes.
  90.  */
  91.  
  92. void CExpanderHeader :: MakeComponents( void )
  93. {
  94.     MakeExpanderButton();
  95.     AppendChild( MakeExpanderLabel() );
  96. }
  97.  
  98.  
  99. void CExpanderHeader :: MakeExpanderButton( void )
  100. {
  101.     short aWidth = kExpanderButtonSize;
  102.     short aHeight = kExpanderButtonSize;
  103.  
  104.     /*
  105.      * Create button. NOTE: we don't treat the button as a child. Otherwise, our label
  106.      * would be positioned BELOW the button (CColumnizer behavior). We just treat this
  107.      * as a normal pane, and offset the label so they won't overlap.
  108.      */
  109.     itsButton = TCL_NEW( CExpanderButton, ( this, itsSupervisor, aWidth, aHeight ) );
  110. }
  111.  
  112.  
  113. CExpanderLabel *CExpanderHeader :: MakeExpanderLabel( void )
  114. {
  115.     short    aWidth = width - ( kExpanderButtonSize + 4 );
  116.     short    aHeight = kExpanderButtonSize + 4;
  117.     short    aHLoc = kExpanderButtonSize + 4;
  118.     short    hVLoc = 0;
  119.  
  120.     itsLabel = TCL_NEW( CExpanderLabel, ( this, itsSupervisor, aWidth, aHeight, aHLoc, aVLoc,
  121.                                           sizFIXEDSTICKY, sizFIXEDSTICKY );
  122. }
  123.  
  124.  
  125. /*
  126.  * PutTo method - OVERRIDE
  127.  *
  128.  * Writes to the stream all the info we need to save.
  129.  */
  130.  
  131. void CExpanderHeader :: PutTo( CStream &stream )
  132. {
  133.     CExpanderPane::PutTo( stream );
  134.  
  135.     stream << itsLabel;
  136.     stream << itsButton;
  137. }
  138.  
  139.  
  140. /*
  141.  * GetFrom method - OVERRIDE
  142.  *
  143.  * Reads from the stream all of the info that we saved.
  144.  */
  145.  
  146. void CExpanderHeader :: GetFrom( CStream &stream )
  147. {
  148.     CExpanderPane::GetFrom( stream );
  149.  
  150.     itsLabel = (CExpanderLabel *)stream.GetView( this, itsSupervisor );
  151.     itsButton = (CExpanderButton *)stream.GetView( this, itsSupervisor );
  152. }
  153.